﻿#region copyright
// Halcyone - Silverlight Application Framework
// Copyright (C) 2009 - 2010 Alexey Zakharov (B&Z LLC)
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#endregion
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Witcraft.Halcyone.ServiceModel;

namespace ServiceModel.Tests
{
    using System.IO;
    using System.Runtime.Serialization.Json;

    [TestClass]
    public class ObjectExtensionsTests
    {
        [TestMethod]
        public void ToUriCompatibleString_Valid()
        {
            Assert.AreEqual("03-01-2009", new DateTime(2009, 3, 1).ToUriCompatibleString());
            Assert.AreEqual("2.4545", 2.4545.ToUriCompatibleString());
            Assert.AreEqual("[1,2,3,4,5]", (new[] { 1, 2, 3, 4, 5 }).ToUriCompatibleString());
            Assert.AreEqual("[3.453,5.4533]", (new[] { 3.453, 5.4533 }).ToUriCompatibleString());
        }


        [TestMethod]
        public void ToUriCompatibleString_Nullable()
        {
            DateTime? dateTime = new DateTime(2009, 02, 02);
            Assert.AreEqual("02-02-2009", dateTime.ToUriCompatibleString());
        }

        [TestMethod]
        public void ToUriCompatibleString_Class()
        {
            var foo = new Foo()
                {
                    Name = "Foo",
                    Price = 123
                };
            var result = foo.ToUriCompatibleString();

            Assert.AreEqual("{\"Name\":\"Foo\",\"Price\":123}", result);
        }

    }

    public class Foo
    {
        public string Name { get; set; }
        public int Price { get; set; }
    }
}